package cn.fbs.controller;

import cn.fbs.model.NewTCodeTargetType;
import cn.fbs.model.NewTcodeTargetTree;
import cn.fbs.service.NewTargetService;
import cn.fbs.vo.NewTargetVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "New 目标管理")
@RestController
@RequestMapping("newTarget")
public class NewTargetController {

    @Autowired
    NewTargetService newTargetService;


    /**
     * @Description: 查询指标全部层级关系
     * @Param: []
     * @return: com.bonc.entity.ResponseEntity
     * @Author: zlj
     * @Date: 2020/12/22
     **/
    @ApiOperation("查询目标全部层级关系")
    @RequestMapping(value = "getTargetTree", method = RequestMethod.GET)
    public List<NewTcodeTargetTree> getCategoryTree() {
        List<NewTcodeTargetTree> categoryTree = newTargetService.getTargetTree();
        return categoryTree;
    }

//    @ApiOperation("查询所有的目标-按照树形结构返回")
    @GetMapping("findAllByTree")
    public List<NewTcodeTargetTree> findAllByTree() {
        return newTargetService.findAllByTree();
    }


    @GetMapping("/getCurrentChildrenTarget")
    @ApiOperation("获取当前目标下的子目标")
    @ApiImplicitParam(name = "zbnm",value = "当前目标的装备内码",required = true)
    public List<NewTcodeTargetTree> getCurrentChildrenTarget(@RequestParam(value = "zbnm",required = false) String zbnm){
         System.out.println("getCurrentChildrenTarget");  return newTargetService.getChildrens(zbnm);
    }

    @ApiOperation("新增目标")
    @PostMapping("add")
    public String insert( @RequestBody @ApiParam("目标实体") NewTargetVo targetVo) {
        return newTargetService.insert(targetVo);

    }


    @ApiOperation("更新目标")
    @PostMapping("update")
    public String update(@RequestBody @ApiParam("目标实体") NewTCodeTargetType targetType) {
         System.out.println("update");
       int result= newTargetService.update(targetType);
      if(result==-1){
        return "401,已存在相同名称的目标!";
      }
      return "200,操作成功";
    }

    @ApiOperation("根据zbnm删除目标")
    @GetMapping("delete")
    @ApiImplicitParam(name = "zbnm",value = "当前目标的zbnm",required = true)
    public Map<String, Object> delete(String zbnm) {
         return newTargetService.delete(zbnm);
    }

    @ApiOperation("根据zbnm查询当前目标下有无子集数据")
    @GetMapping("getMessageByNm")
    @ApiImplicitParam(name = "zbnm",value = "当前目标的zbnm",required = true)
    public Map<String, Object> getMessageByNm(String zbnm){
         System.out.println("getMessageByNm");
        return newTargetService.getMessageByNm(zbnm);
    }


    @ApiOperation("根据MC查询目标")
    @GetMapping("/getTargetByMC")
    @ApiImplicitParam(name = "mc",value = "目标的名称")
    public List<NewTCodeTargetType> getTargetByMC(String mc){
       List<NewTCodeTargetType> list =  newTargetService.getTargetByMC(mc);
        System.out.println("getTargetByMC");
       return list;
    }
}
